package com.jzo2o.orders.manager.service.client;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.jzo2o.api.customer.AddressBookApi;
import com.jzo2o.api.customer.dto.response.AddressBookResDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 调用customer的客户端类
 */
@Slf4j
@Component
public class CustomerClient {

    @Autowired
    private AddressBookApi addressBookApi;

    /**
     * 根据ID查询地址簿
     *
     * @return
     */
    @SentinelResource(value = "getDetail", fallback = "getDetailFallback", blockHandler = "getDetailBlockHandler")
    public AddressBookResDTO getDetail(Long id){
        return addressBookApi.detail(id);
    }

    /**
     * 根据ID查询地址簿[降级处理]
     * @param id
     * @return
     */
    public AddressBookResDTO getDetailFallback(Long id, Throwable e){
        log.error("普通降级处理，地址簿id：{}",id);
        return null;
    }

    /**
     * 根据ID查询地址簿[熔断处理]
     * @param id
     * @return
     */
    public AddressBookResDTO getDetailBlockHandler(Long id, BlockException e){
        log.error("熔断降级处理，地址簿id：{}",id);
        return null;
    }
}
